
<template>
  <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      >
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="维修原因">
        <el-input v-model="form.reason"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="submit">确 定</el-button>
  </span>
  </el-dialog>
</template>
<script>
import {_subRepair} from '../../../api/student'

export default {
  data () {
    return {
      dialogVisible: false,
      form: {
        reason: ''
      }
    }
  },
  methods: {
    show () {
      this.dialogVisible = true
    },
    submit () {
      if (JSON.parse(localStorage.getItem('user')).room === null) {
        this.$message({
          message: '您还未入住，无法提交维修申请',
          type: 'error'
        })
        return
      }
      _subRepair(JSON.parse(localStorage.getItem('user')).id, this.form.reason).then(res => {
        if (res.status) {
          this.$message({
            message: '维修申请提交成功',
            type: 'success'
          })
          this.dialogVisible = false
        } else {
          this.$message({
            message: '维修申请提交失败',
            type: 'error'
          })
        }
      })
    }
  }
}
</script>
<style scoped>

</style>
